//
//  SPDataCPFSelectView.m
//  panzer
//
//  Created by 还带大道 on 2018/10/24.
//  Copyright © 2018年 还带大道. All rights reserved.
//

#import "SPDataCPFSelectView.h"
#import "SPDataCModel.h"

@interface SPDataCPFSelectView()
@property (weak, nonatomic) IBOutlet UIView *view1;
@property (weak, nonatomic) IBOutlet UIView *view2;
@property (weak, nonatomic) IBOutlet UIView *view3;

@property (weak, nonatomic) IBOutlet UILabel *join;
@property (weak, nonatomic) IBOutlet UILabel *no_join;
@property (weak, nonatomic) IBOutlet UILabel *liveCount;

@property (weak, nonatomic) IBOutlet UILabel *all_title;
@property (weak, nonatomic) IBOutlet UILabel *man_title;
@property (weak, nonatomic) IBOutlet UILabel *woman_title;

@property (weak, nonatomic) IBOutlet UILabel *allCount;
@property (weak, nonatomic) IBOutlet UIView *view_all;
@property (weak, nonatomic) IBOutlet UILabel *manCount;
@property (weak, nonatomic) IBOutlet UIView *view_man;
@property (weak, nonatomic) IBOutlet UILabel *womanCount;
@property (weak, nonatomic) IBOutlet UIView *view_woman;

@end

@implementation SPDataCPFSelectView

+ (instancetype)shareHeaderView
{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil].lastObject;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self setShadowColorWithView:_view1];
    [self setShadowColorWithView:_view2];

    _view1.backgroundColor = [UIColor whiteColor];
    _view2.backgroundColor = [UIColor whiteColor];
    _view3.backgroundColor = [UIColor whiteColor];
    _view_all.backgroundColor = [UIColor whiteColor];
    _view_woman.backgroundColor = [UIColor whiteColor];
    _view_man.backgroundColor = [UIColor whiteColor];
    
    //设置默认选中
    [self all];
}

- (void)setShadowColorWithView:(UIView *)view
{
    view.layer.shadowColor = RZ_COLOR_ALPHA(187, 183, 183, 0.5).CGColor;
    view.layer.cornerRadius = 4;
    view.layer.shadowOffset = CGSizeMake(0,1);//shadowOffset阴影偏移,x向右偏移，y向下偏移，默认(0, -3)
    view.layer.shadowOpacity = 1;//阴影透明度，默认0
    view.layer.shadowRadius = 9;//阴影半径，默认3
}


- (IBAction)all {
    [self setupSelectedWithGenderType:GenderType_ALL];
    !self.genderSwitchBlock?:self.genderSwitchBlock(GenderType_ALL);
}


- (IBAction)man {
    [self setupSelectedWithGenderType:GenderType_MAN];
   !self.genderSwitchBlock?:self.genderSwitchBlock(GenderType_MAN);
}

- (IBAction)woman {
    [self setupSelectedWithGenderType:GenderType_WOMAN];
   !self.genderSwitchBlock?:self.genderSwitchBlock(GenderType_WOMAN);
}


- (void)setupSelectedWithGenderType:(GenderType)type
{
    [self setupSelectedWithView:_view_all lable:_all_title selected:type == GenderType_ALL];
    [self setupSelectedWithView:_view_man lable:_man_title selected:type == GenderType_MAN];
    [self setupSelectedWithView:_view_woman lable:_woman_title selected:type == GenderType_WOMAN];
}



- (void)setupSelectedWithView:(UIView *)view lable:(UILabel *)label selected:(BOOL)selected
{
    if(selected){
        view.backgroundColor = RZ_COLOR(253, 215, 54);
        label.textColor = RZ_COLOR(74, 74, 74);
    }else{
        view.backgroundColor = [UIColor whiteColor];
        label.textColor = RZ_COLOR(155, 155, 155);
    }
}

- (void)setType:(GenderType)type
{
    _type = type;
    [self setupSelectedWithGenderType:type];
}


- (void)setModel:(SPDataCModel *)model
{
    _model = model;
    _join.text = [NSString stringWithFormat:@"%ld",model.total_man_entry];
    _no_join.text = [NSString stringWithFormat:@"%ld",model.total_man_notEntry];
    _liveCount.text = [NSString stringWithFormat:@"%d",0];
    _manCount.text = [NSString stringWithFormat:@"%ld",model.total_man_nan];
    _womanCount.text = [NSString stringWithFormat:@"%ld",model.total_man_nv];
    _allCount.text = [NSString stringWithFormat:@"%ld",model.total_man_nan+model.total_man_nv];
}

@end
